package tk.mybatis.simple;

import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSession;
import tk.mybatis.simple.mapper.CountryMapper;
import tk.mybatis.simple.model.Country;

import java.util.HashSet;
import java.util.List;

/**
 * @author liuzh
 * @since 2017/10/31.
 */
public class SimpleTest {

    public static void main(String[] args) throws Exception {
        SqlSession sqlSession = SqlSessionHelper.getSqlSession();
        Configuration configuration = sqlSession.getConfiguration();
        HashSet<MappedStatement> mappedStatements
                = new HashSet<MappedStatement>(configuration.getMappedStatements());
        for (MappedStatement ms : mappedStatements) {
            SimpleMapperHelper.changeMs(ms);
        }
        //替换后执行该方法
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Country query = new Country();
        query.setCountrycode("CN");
        List<Country> countryList = mapper.select(query);
        for (Country country : countryList) {
            System.out.printf(country.toString());
        }
        sqlSession.close();
    }
}
